package miku.firstgame.ui.card
{
	import com.saia.starlingPunk.SPEntity;

	import miku.firstgame.model.gold.card.ToolCard;
	import miku.firstgame.model.gold.interfaces.ICard;

	public class ToolCardUI extends CardUI
	{

		/**
		 * 上次移动中激活的位置
		 * */
		private var lastObject:UserSeat;

		public function ToolCardUI(card:ICard)
		{
			super(card);
		}

		public function get toolCard():ToolCard
		{
			return card as ToolCard;
		}

		public function get isDestroy():Boolean
		{
			return toolCard.isDestroy;
		}

		public function get toolType():int
		{
			return toolCard.toolType;
		}

		override protected function doCollide():void
		{
			var collideObject:UserSeat = collide("userSeat", this.x, this.y) as UserSeat;
			if (collideObject && collideObject.haveUser) //碰到的座位有人
			{
				if (collideObject != lastObject)
				{
					if (lastObject)
					{
						lastObject.selected = false;
					}

					if (collideObject.canApplyToolCard(this.toolCard))
					{
						collideObject.selected = true;
					}
					else
					{
						collideObject.selected = false;
					}

					lastObject = collideObject;
				}
			}
			else
			{
				if (lastObject)
				{
					lastObject.selected = false;
					lastObject = null;
				}
			}
		}
	}
}
